package com.example.demo.base.controller;

import com.google.common.collect.Lists;
import lombok.Data;
import org.reactivestreams.Publisher;
import org.reactivestreams.Subscriber;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.util.pattern.PathPattern;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * @Auther: miaoguoxin
 * @Date: 2020/3/21 16:04
 * @Description:
 */
@RestController
public class HelloWebFluxController {
    @Data
    public class User{
        private String name;
        private String desc;
    }
    @GetMapping("/hello")
    public String hello() {
        return "Hello, WebFlux !";
    }

    @GetMapping("/user")
    public Mono<User> getUser() {
        User user = new User();
        user.setName("犬小哈");
        user.setDesc("欢迎关注我的公众号: 小哈学Java");
        return Mono.just(user);
    }

    @GetMapping("/flux_user")
    public Flux<User> getUserFlux(){
        User user = new User();
        user.setName("犬小哈");
        user.setDesc("欢迎关注我的公众号: 小1123哈学Java");
        List<User> users = new ArrayList<User>();
        users.add(user);
       return Flux.just(user,user);
    }

    public static void main(String[] args) {
        List<String> a = Lists.newArrayList("/muser/**");
        Optional<String> optionalPathPattern = a.stream()
                .filter(pattern -> pattern.matches("/muser/user/test")).findFirst();
        System.out.println(optionalPathPattern.isPresent());
        boolean matches = "/muser/**".matches("/muser/user/test");
        System.out.println(matches);
    }
}

